package com.study.spark.scala.chapter08

object Scala05_Match {
  def main(args: Array[String]): Unit = {
    // TODO　模糊查询 - 匹配规则
    // 匹配对象
    val user = getUser()

    user match {
      case User("zhangsan",10) => println("用户为张三")
      case _ => println("什么也不是")
    }



    }

  class User {
    var name: String = _
    var age: Int = _

  }

  object User{

    // 对象 => 属性
    def unapply(arg: User): Option[(String,Int)] ={
      Option(arg.name,arg.age)
    }
    // 属性 => 对象
    def apply(name : String , age :Int): User ={
      val user = new User()
      user.name=name
      user.age=age
      user
    }
  }


  def getUser(): User ={
    User("zhangsan",20)
  }




}
